<?php
namespace app\api\controller;
use app\common\model\Question as QuestionModel;
use app\common\model\Pk as PkModel;
use app\common\model\User;
class Customer extends Base
{
  public function questionList () {
    $list = QuestionModel::getAll(1,'ord desc');
    if(!$list) {
      $this->ajax(200,'success',[]);
    }
    foreach($list as $k=>$v) {
      //$list[$k]['content'] = nl2br($v['content']);
    }
    $this->ajax(200,'success',$list);
  }

  /* pk活动详情 */
  public function pkDetail () {
    $detail = PkModel::getOne([
      'status' => 1
    ]);
    if(strtotime($detail['end_time'])<time()) {
      $detail['status'] = 0;
    }
    $detail['sale_money_all'] = $detail['sale_money_all']+$detail['sale_money'];//总销售额
    $detail['prize_money'] = round($detail['sale_money']*$detail['prize_bili'],2);
    //$detail['end_timestamp'] = strtotime($detail['end_time'])-time();
    $detail['end_timestamp'] = strtotime($detail['end_time']);
    $detail['prize1'] = (int)($detail['prize_money']*0.5);
    $detail['prize2'] = (int)($detail['prize_money']*0.1);
    $detail['prize3'] = (int)($detail['prize_money']*0.05);
    $detail['prize_other'] = (int)($detail['prize_money']*0.35/17);
    $detail['content'] = nl2br($detail['content']);
    $list = User::getPage([
      'grade_id' => [
        'egt',1
      ]
    ],1,20,'id desc','id,headimgurl,nickname,grade_id');
    foreach($list as $k=>$v) {
      $list[$k]['sale_money'] = (-$k+20)*10000;
      if($k==0) {
        $list[$k]['money'] = $detail['prize1'];
      }elseif($k==1) {
        $list[$k]['money'] = $detail['prize2'];
      }elseif($k==2) {
        $list[$k]['money'] = $detail['prize3'];
      }else{
        $list[$k]['money'] = $detail['prize_other'];
      }
    }
    $detail['list'] = $list;
    $this->ajax(200,'success',$detail);
  }
}